<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
    $params=array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'is_agent'=>1);
	if($_RQ['status']){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),		
	);
	$list=$this->get_list('member',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['agent']=cfc('core')->member_show($item['fromuser']);
			$item['commission_1']=$this->sum('commission',array('merchid'=>$merchid,'status <='=>1,'mid'=>$item['mid']),'money');
			$item['commission_2']=$this->sum('commission',array('merchid'=>$merchid,'status'=>2,'mid'=>$item['mid']),'money');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','tip'=>'【温馨提示】：</br>1、佣金汇总显示！','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'mid','title'=>'MID','type'=>'string'),
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'level_id','title'=>'代理等级','type'=>'select','options'=>'levels'),
            array('name'=>'commission_2','title'=>'已结算','type'=>'string'),
			array('name'=>'commission_1','title'=>'待结算','type'=>'string'),
		)),
		'search'=>array(
			array('type'=>'radio','width'=>15,'name'=>'status','title'=>'状态','options'=>'agent_status'),
			array('type'=>'choose','width'=>18,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		),
	);
	$return['htmls']=$htmls;
	$return['agent_status']=$this->agent_status;
    $return['levels']=$this->getall('level',array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
    $return['levels']['0']=array('id'=>'0','title'=>'预选代理');
	exi($return);
}
?>